<template>
  <div>
    <div
      class="wrapper-container" style="display: flex; flex-direction: column; width: 100%">
      <div class="search-container">
        <div class="search-container-left" style="display: flex; align-items: center;">
          <div
          style="margin-left: 20px;"
            class="search-container-item"
            v-for="(select, index) in selectList"
            :key="index"
          >
            <div v-if="select.type === 'select'" class="box">
              <span v-show="select.name" style="120px">{{ select.name }}</span>
              <el-select
                v-model="select.val"
                style="width: 120px"
                size="mini"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in select.valList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </div>
            <div class="box" v-if="select.type === 'data'">
              <span class="demonstration" v-show="select.name">{{
                select.name
              }}</span>
              <el-date-picker
                v-model="select.val"
                type="date"
                placeholder="选择日期"
                prefix-icon="aaa"
              >
              </el-date-picker>
            </div>
            <div v-if="select.type === 'MultiSelect'" class="box"></div>
            <div v-if="select.type === 'btn'" class="box">
              <span class="demonstration" v-show="select.name" style="width:120px">{{
                select.name
              }}</span>
              <el-input
                v-model="select.val"
                placeholder="请输入内容"
              ></el-input>
            </div>
          </div>
          <div class="search-button" style="margin-left: 20px" @click="queryTimeTable">
            <img src="../../../../assets/assessment/icon-search.png" alt="" />
            <span>查询</span>
          </div>
        </div>
        <div class="export-top" style="float: right;margin-right: 10px;" @click="exportData">
        <img src="../../../../assets/assessment/icon-export.png" alt="" />
        <span>&ensp;导出Excel</span>
      </div>
      </div>
    </div>
    
    <div class="body-manual-container">
      <div>
        <ul>
          <li>
            <span><div>节次</div></span>
            <span><div>星期一</div></span>
            <span><div>星期二</div></span>
            <span><div>星期三</div></span>
            <span><div>星期四</div></span>
            <span><div>星期五</div></span>
            <span><div>星期六</div></span>
            <span><div>星期日</div></span>
          </li>
          <li v-for="(item,key) in tableList" :key="key">
            <span>
              <div>
                <div>{{ item.jc }}</div>
              </div>
            </span>
            <span>
              <div>
                <div>{{ item.w1 }}</div>
              </div>
            </span>
            <span>
              <div>
                <div>{{ item.w2 }}</div>
              </div>
            </span>
            <span>
              <div>
                <div>{{ item.w3 }}</div>
              </div>
            </span>
            <span>
              <div>
                <div>{{ item.w4 }}</div>
              </div>
            </span>
            <span>
              <div>
                <div>{{ item.w5 }}</div>
              </div>
            </span>
            <span>
              <div>
                <div>{{ item.w6 }}</div>
              </div>
            </span>
            <span>
              <div>
                <div>{{ item.w7 }}</div>
              </div>
            </span>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import {
  queryTimeTable, queryTimeTable_Export,
} from "@/api/trainingManagement/place.js";

export default {
  data() {
    return {
      userRole: "", //用户角色 admin 管理员, other
      tableList: {}, //
      selectList: [
        {
          type: "btn",
          name: "教员姓名:",
          val: "",
        },
      ],
      jsonFields: {
      节次: "jc", //节次
      星期一: "w1",
      星期二: "w2",
      星期三: "w3",
      星期四: "w4",
      星期五: "w5",
      星期六: "w6",
      星期日: "w7",
      },
    };
  },
  created() {},
  mounted() {
    this.userInfo = JSON.parse(localStorage.getItem("xpaasui-userInfo"))
    this.userRole = this.userInfo.content.role_name;
    if (this.userRole != "strator") {
      this.selectList.push({
        type: "select",
        name: "课表类型:",
        val: "专业班次课表",
        valList: [
          {
            label: "专业班次课表",
            value: "专业班次课表",
          },
          {
            label: "场地课表",
            value: "场地课表",
          },
        ],
      });
    }
    this.queryTimeTable();
  },
  methods: {
    async queryTimeTable() {
      var name = this.selectList[0].val; //教员姓名
      var type = "";
      if (this.userRole != "strator") {
        type = this.selectList[1].val;
      }
      const res = await queryTimeTable(name, type);
      if (res.data.code == 200) {
        this.tableList = res.data.data;
      }
    },
    // 导出
    exportData() {
      var name = this.selectList[0].val; //教员姓名
      var type = "";
      if (this.userRole != "strator") {
        type = this.selectList[1].val;
      }
      console.log(name, type , '111111111111')
      queryTimeTable_Export(name, type).then((res) => {
        /** 获取生成设置好的文件名 */
        // var filename = res.headers["content-disposition"];
        // filename = filename.split("=")[1];
        // // 我看好多博客此处没有再次编码，我这里不重新编码，文件名称总是乱码
        // filename = escape(filename);
        // filename = decodeURIComponent(filename, "utf-8");
        // console.log(filename);
        // console.log(res.data);
        /** 接收文件流 */
        const blob = new Blob([res.data]);
        let url = URL.createObjectURL(blob);
        /** 模拟浏览器操作Document，并模拟下载动作 */
        let link = document.createElement("a");
        link.style.display = "none";
        link.href = url;
        link.setAttribute("download", "课表.xlsx");
        document.body.appendChild(link);
        link.click();
      });
    },
  },
  computed: {}, //计算属性
};
</script>
<style lang="less" scoped>
@import "../../../../styles/supervision.less";
@import "../../../../styles/applicationDeferment.less";
.wrapper-container .search-container .search-container-left {
  width: 100%;
  flex-wrap: wrap;
  .search-container-item {
    width: 12%;
    margin-right: 0px;
    .box {
      > span {
        text-align: left;
      }
      display: flex;
      justify-content: space-evenly;
      align-items: center;
      /deep/ .el-input__inner {
        height: 28px;
      }
    }
  }
}

/deep/.el-date-editor.el-input {
  width: 110px;
}
/deep/ .el-input--medium {
  width: 110px;
  .el-input__inner {
    height: 28px;
    width: 110px;
    padding: 0px 18px;
  }
}
/deep/ .el-table thead {
  color: #004ca7 !important;
}

.btn {
  margin-top: 271px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 271px;
  .submit {
    width: 84px;
    height: 27px;
    line-height: 8px;
  }
}
.bottom-block {
  flex-direction: row;
  justify-content: space-between !important;
  .export-button {
    width: 127px;
    height: 27px;
    background: #fff6ef;
    border: 1px solid #f3b815;
    border-radius: 4px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    margin-top: 14px;
    > img {
      width: 17px;
      height: 17px;
    }
    > span {
      margin-left: 12px;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #f3b815;
    }
  }
  .text {
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    line-height: 39px;
    color: #004ca7;
  }
}

.body-manual-container {
  > div:nth-child(1) {
    width: calc(100% - 20px);
    border: 1px solid rgba(0, 76, 167, 0.8);
    border-radius: 6px;
    margin: 30px auto 0;
    ul {
      list-style: none;
      li:nth-child(n) {
        border-bottom: 1px solid rgba(0, 76, 167, 0.4);
        height: auto;
        > span {
          box-sizing: border-box;
          display: inline-block;
          font-size: 14px;
          color: rgba(0, 76, 167, 1);
          border-right: 1px solid rgba(0, 76, 167, 0.4);
          height: 60px;
          vertical-align: middle;
          &:nth-child(n) {
            width: 12.5%;
            height: 100px;
          }
          &:last-child {
            border-right: none;
          }
          &.active {
            font-size: 16px;
            color: rgba(0, 76, 167, 1);
            font-weight: bold;
            background: rgba(77, 129, 192, 0.1);
            text-align: center;
            padding-left: 0;
          }
          > span {
            color: rgba(255, 56, 25, 1);
          }
          > div {
            width: 100%;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
          }
        }
      }
      li:nth-child(1) {
        > span {
          &:nth-child(n) {
            width: 12.5%;
            height: 60px;
            font-weight: bold;
          }
          > div {
            width: 100%;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 16px;
          }
        }
      }
    }
  }
}

.export-right {
  display: flex;
  align-items: center;
  justify-content: end;
  margin-top: -60px;
}

.export-button {
    cursor: pointer;
  }
.export-top {
  
    cursor: pointer;
    width: 127px;
    height: 28px;
    background: #fff6ef;
    border: 1px solid #f3b815;
    border-radius: 4px;
    display: flex;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    flex-direction: row;
    -webkit-box-align: center;
    align-items: center;
    -webkit-box-pack: center;
    justify-content: center;
    > img {
      width: 17px;
      height: 17px;
    }
    > span {
      color: #f3b815;
    }
}
</style>
